public class Main {
    private static final int MOD = 10000007;

    public static int solution(int n, int A, int B, int[] arrayA) {
        assert A <= 9 && B <= 9;
        assert n == arrayA.length;

        int[][] dp = new int[n + 1][10];
        int sumValue = 0;
        for (int num : arrayA) {
            sumValue = (sumValue + num) % 10;
        }
        int ret = (A + B) % 10;
        int res = 0;

        if (sumValue == B) {
            res++;
        }

        dp[0][0] = 1;
        if (sumValue == ret) {
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j < 10; j++) {
                    int prev = (j - arrayA[i - 1]) % 10;
                    if (prev < 0) prev += 10;
                    dp[i][j] = (dp[i - 1][j] + dp[i - 1][prev]) % MOD;
                }
            }
            return (dp[n][A] + res) % MOD;
        } else {
            if (sumValue == A) {
                res++;
            }
            return res;
        }
    }

    public static void main(String[] args) {
        System.out.println(solution(3, 1, 2, new int[]{1,1,1}) == 3);
        System.out.println(solution(3, 3, 5, new int[]{1,1,1}) == 1);
        System.out.println(solution(2, 1, 1, new int[]{1,1}) == 2);
    }
}
